﻿using System.ComponentModel.Composition;
using System.Windows;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;

namespace CodeJumper
{

    #region CodeJumper Factory

    /// <summary>
    /// Export a <see cref="IWpfTextViewMarginProvider"/>, which returns an instance of the margin for the editor
    /// to use.
    /// </summary>
    [Export(typeof (IWpfTextViewMarginProvider))]
    [Name(CodeJumper.MarginName)]
    [Order(After = PredefinedMarginNames.VerticalScrollBar)] //Ensure that the margin occurs below the horizontal scrollbar
    [MarginContainer(PredefinedMarginNames.Right)] //Set the container to the bottom of the editor window
    [ContentType("code")] //Show this margin for all text-based types
    [TextViewRole(PredefinedTextViewRoles.PrimaryDocument)]
    internal sealed class MarginFactoryRight : IWpfTextViewMarginProvider
    {
        #region IWpfTextViewMarginProvider Members

        public IWpfTextViewMargin CreateMargin(IWpfTextViewHost textViewHost, IWpfTextViewMargin containerMargin)
        {
            if (textViewHost.TextView.TextBuffer.ContentType.TypeName != "CSharp" &&
                textViewHost.TextView.TextBuffer.ContentType.TypeName != "Basic" &&
                textViewHost.TextView.TextBuffer.ContentType.TypeName != "C/C++"
                )
            {
                return null;
            }

            if (PluginConfiguration.Instance.PluginLocation != PluginLocation.Right)
                return null;

            return new CodeJumper(textViewHost.TextView, new Thickness(5, 0, 0, 0), HorizontalAlignment.Left);
        }

        #endregion
    }

    #endregion
}